//
//  StateBoot.swift
//  SwiftUIWidgetDemo
//
//  Created by alanzhangg on 2023/7/12.
//

import SwiftUI

struct StateBoot: View {
    
    @State var backgroundColor: Color = .green
    @State var myTitle: String = "my title"
    @State var count: Int = 0
    
    var body: some View {
        ZStack{
            backgroundColor
                .ignoresSafeArea()
            VStack(spacing: 20, content: {
                Text("title")
                    .font(.title)
                    
                Text("count: \(count)")
                    .font(.headline)
                    .underline()
                
                HStack(spacing:20, content: {
                    Button {
                        backgroundColor = .red
                        myTitle = "button 1 was pressed"
                        count += 1
                    } label: {
                        Text("button 1")
                    }
                    
                    Button("button 2") {
                        backgroundColor = .purple
                        myTitle = "button 2 was pressed"
                        count -= 1
                    }

                })
            })
            .foregroundStyle(.white)
        }
    }
}

#Preview {
    StateBoot()
}
